const { ccclass, property } = cc._decorator;

/**动画快捷控制类，可以控制动画的播放时间等 */
@ccclass
export default class AnimationQuickControl extends cc.Component {

    @property
    autoPlay: boolean = false;

    @property({
        tooltip: "重复触发时间间隔"
    })
    interval: number = 5;

    @property({
        tooltip: "重复次数"
    })
    repeat: number = -1;

    @property({
        tooltip: "延时开始时间"
    })
    delay: number = 0;

    @property({
        type:cc.Animation,
        visible:false,
    })
    animation : cc.Animation = null;

    onLoad () {

        this.animation = this.getComponent(cc.Animation);
    }

    start () {

    }

    onEnable(){

        if (this.autoPlay) {

            if (this.animation != null) {

                this.schedule(this.playAnimation, this.interval, this.repeat, this.delay);
            }
        }
    }

    onDisable(){

        if (this.autoPlay) {

            if (this.animation != null) {

                this.unschedule(this.playAnimation);
            }
        }
    }

    playAnimation(){

        this.animation.play();
    }
}
